﻿using System;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class DefColWidthRecord : BiffRecord
    {
        private ushort cchdefColWidth = 8;

        protected override void ReadContent(BiffReaderContext context, int length)
        {
            cchdefColWidth  = context.ReadUInt16();
        }

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.DefColWidth; }
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            if (context.DefColumnWidthInIndex != 0)
            {
                var pos = context.Position;
                using (var c = context.CreateMovedContext(context.DefColumnWidthInIndex))
                {
                    context.Write((uint)pos - 4);
                }
            }
            context.Writer.Write(cchdefColWidth);
        }
    }
}